package com.cloudptt.api.product.config.msg;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.preference.PreferenceManager;

import com.cloudptt.api.product.log.Log;
import com.mcptt.db.model.SessionInfo;

public class MsgConfig
{
	
	private static String THIS_FILE = "MsgConfig";
	public static final String Key_ReceiptRecv = "msg_receipt_recv";
	public static final String Key_ReceiptRead = "msg_receipt_read";
	public static final String Key_ReceiptDownload = "msg_receipt_download";

	private SharedPreferences sp = null;
	private boolean receiptRecv = false;
	private boolean receiptRead = false;
	private boolean receiptDownload = false;
	
	public MsgConfig(SharedPreferences sp)
	{
		this.sp = sp;
		this.receiptRecv = sp.getBoolean(Key_ReceiptRecv,false);
		this.receiptRead = sp.getBoolean(Key_ReceiptRead,false);
		this.receiptDownload = sp.getBoolean(Key_ReceiptDownload,false);
	}
//	
public void setReceiptRecv(boolean receiptRecv,boolean receiptRead,boolean receiptDownload) {
	this.receiptRecv = receiptRecv;
	this.receiptRead = receiptRead;
	this.receiptDownload = receiptDownload;

	SharedPreferences.Editor editor = sp.edit();
	editor.putBoolean(Key_ReceiptRecv, receiptRecv);
	editor.putBoolean(Key_ReceiptRead, receiptRead);
	editor.putBoolean(Key_ReceiptDownload, receiptDownload);

	editor.commit();
}
	public boolean isReceiptRecv() {
		return receiptRecv;
	}
	public boolean isReceiptRead() {
		return receiptRead;
	}
	public boolean isReceiptDownload() {
		return receiptDownload;
	}
	public int getDispositionReqType(boolean isFdMsg)
	{
		if(isFdMsg)
		{
			return getFdReceiptValue();
		}
		else
		{
			return getSdsReceiptValue();
		}
	}
	private int getSdsReceiptValue()
	{
		int value = 0;
		if(receiptRecv)
		{
			value = value + SessionInfo.DELIVERY;
		}
		if(receiptRead)
		{
			value = value + SessionInfo.READ;
		}
		return value;
	}
	private int getFdReceiptValue()
	{
		int value = 0;
		if(receiptDownload)
		{
			value = value + SessionInfo.DOWNLAOD;
		}
		return value;
	}
}
